package IO流;

import java.io.File;

/**
 *统计文件夹大小
 *
 * */
public class File02 {
    public static void main(String[] args) {
        File src = new File("C:\\huangzhi\\workspace\\javaStudy");
        count(src);
        System.out.println(len);
    }

    private static long len = 0;
    private static void count(File src) {
        //获取大小
        if(null != src||src.exists()){
            //是文件则计算大小并叠加
            if (src.isFile()){
                len += src.length();
            }else {//进入其子孙级，递归其大小
                for (File f : src.listFiles()){
                    count(f);
                }
            }
        }
    }
}
